/**
 * 医生端的视频记录
 */
var uid, name, avatar, ws;
document.addEventListener('plusready', function(){
	ws = plus.webview.currentWebview();
	uid = plus.storage.getItem('uid');
	name = plus.storage.getItem('name');
	avatar = plus.storage.getItem('avatar');
	if(avatar && avatar.indexOf('http') < 0){
		avatar = webRoot + avatar;
	}
	showWating();
	console.log(apiRoot+"/home/chat/videoList/uid/"+uid+"/type/receiveid")
	$.ajax({
		type :"get",
		url :apiRoot+"/home/chat/videoList",
		data :{
			uid :uid, 
			type :'receiveid'
		},
		dataType :'json',
		success :function(data){
			console.log(JSON.stringify(data));
			plus.nativeUI.closeWaiting();
			if(data.length > 0){
				var list = '';
				$.each(data, function(k, v) {
					list += '<div class="mui-table-view table-view-cell bbs-ico margin-bottom-5" aid="'+v.aid+'" status="'+v.status+'" mid="'+v.mem.aid+'">'+
								'<div class="overflow-h">'+
									'<i><img src="'+getAvatar(v.mem.avatar)+'"/></i>'+
									'<div>'+
										'<li>'+
											'<span>'+v.mem.name+'</span>'+
											'<span class="mui-h6 mui-pull-right">'+v.addtime+'</span>'+
										'</li>'+
										'<li class="mui-h6 ">'+
											'<span class="iconfont type-3">&#xe622;</span>'+
											(v.status == '9' ? '<span>' : '<span style="color:red;">');
								if(v.status == '0'){	//未接通
									if(v.bespeak){
										list += '点击开始 预约时间：'+v.bespeak;
									}else{
										list += '未播通，点击重播';
									}
								}else if(v.status == '1'){	//已接通
									list += '已接通';
								}else if(v.status == '2'){	//拒绝
									list += '已拒绝，点击重播';
								}else if(v.status == '8'){	//因其他因素造成没有发起视频
									list += '未播通，点击重播';
								}else{
									list += '视频已结束'+(v.totaltime ? ('，时长：'+v.totaltime) : '');
								}
								list += '</span></li>'+
									'</div>'+
								'</div>'+
							'</div>';
				});
				$('.mui-content').html(list);
				$('.bbs-ico').unbind('click');
				$('.bbs-ico').on('click',function(){
					var status = $(this).attr('status');//视频状态
					var aid = $(this).attr('aid');//问诊id
					var mid = $(this).attr('mid');//用户id
					console.log(mid+" "+name+" "+avatar);
					if(status == '0' || status == '2' || status == '8'){	//未接通或者拒绝的可以重播
						aid = aid.toString();
//						mui.toast('发起视频，问诊id：'+aid+" "+name+" "+avatar);
						window.plus.bridge.exec("xiangyu","sendVideo",[mid+'',name,avatar, aid+'']);
						ws.close();
					}else{
						goNewPage('free-information-inf.html', {mid:mid, wtype:3});
					}
				})
			}else{
				toast('暂无相关记录');
			}
		},
		error :function(e){
			console.log(JSON.stringify(e));
			errortoast();
		}
	});
}, false)
